<?php
namespace app\baseinfo\controller;

class Areas extends \app\common\controller\Base {
	protected $modelname='Area';

	protected function _index(){
		$condition=[];
		$param=$this->param;
		if (isset($param['name']))
			$condition[]=['name','like',"%".$param['name']."%"];
    if (isset($param['area_no']))
      $condition[]=['id','=', $param['area_no']];
		return $condition;
	}

	public function getLocation() {
		$areaModel = model($this->modelname);
		if ($area=$areaModel::byIP(get_client_ip_from_ns())) {
			return json_pack(['id' => $area->getAttr('id')]);
		} else {
			return json_pack(['id' => 0]);
		}
	}
}

?>